﻿@model Bricks.Site.Models.FlowRecordView
@{
    ViewBag.Title = "BackFlow";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}
<head>
    <title></title>
    <script type="text/javascript">
        $(function () {
            //当页面首次刷新的时候执行的事件
            var flowCode = $("#hFlowCode").val();
            var recordID = $("#hid").val();
            var currentProcessNodeCode = $("#hCurrentProcessNodeCode").val();
            initTable(flowCode, recordID, currentProcessNodeCode);
        });
        //实现对DataGird控件的绑定操作

        function initTable(flowCode, recordID, currentProcessNodeCode) {
            $('#myDataGrid').datagrid({   //定位到Table标签，Table标签的ID是myDataGrid
                //   ActionInfo是控制器，GetData是控制器中获取用户数据的一个Action
                title: '',
                url: '/Flow/SetFlowBackData?flowCode=' + flowCode + '&recordID=' + recordID + '&currentProcessNodeCode=' + currentProcessNodeCode,
                nowrap: true,
                autoRowHeight: false,
                striped: true,
                collapsible: true,
                rownumbers: true,
                remoteSort: false,
                fitColumns: true,
                idField: 'ID',
                singleSelect: true,
                columns: [[
                    {
                        title: '', field: 'ID', width: 50, align: 'center',
                        formatter: function (value, row, index) {
                            return '<input type="radio" name="radiobutton" value="' + row.ID + '"/>';;
                        }
                    },
                    { title: '回退节点', field: 'NodeName', width: 100, sortable: true },
                    { title: '处理人员列表', field: 'NodeProcessDepartmentPerson', width: 250, sortable: true },
                ]],
                onClickRow: function (rowIndex, rowData) {
                    $("input[name='radiobutton']").each(function () {
                        if ($(this).val() == rowData.ID) {
                            $(this).attr("checked", true);
                        }
                    });
                }
            });
        }

        function SaveBackData() {
            var backNodeList = $('#myDataGrid').datagrid('getSelections');
            var backNodeListJson = JSON.stringify(backNodeList);
            var approvalOpinion = $("#taApprovalOpinion").val();
            $('#frmBack').form('submit', {
                url: '/Flow/SaveBackData?backNodeListJson=' + backNodeListJson + '&approvalOpinion=' + approvalOpinion,
                onSubmit: function () {
                    if (backNodeListJson == "[]" || approvalOpinion == "") {
                        $.EasyuiSlide("回退节点和审批意见不能为空！");
                        return false;
                    }
                },
                success: function (data) {
                    window.parent.CloseWindow(3, '回退成功！');
                },
                fail: function (data) {
                    $.EasyuiSlide(data);
                }
            });
        }
    </script>
</head>
<body>
    <div style="padding:5px;">
        <form id="frmBack" method="post">
            <div>
                <input type="hidden" name="FlowCode" id="hFlowCode" value="@Model.FlowCode" />
                <input type="hidden" name="RecordID" id="hid" value="@Model.RecordID" />
                <input type="hidden" name="CurrentFlowNodeCode" id="hCurrentProcessNodeCode" value="@Model.CurrentFlowNodeCode" />
            </div>
        </form>
        <label id="lblTip" style="font-size:15px;font-weight:200;">请选择回退节点</label>
        <div region="top" style="height:180px;">
            <table id="myDataGrid" title="" fit="true"></table>
        </div>
        <div region="center" style="border: solid; margin-top: 5px; height: 90px;width:100%;">
            <table>
                <tr>
                    <td style="padding: 5px 15px 5px 5px; text-align: right; width: 70px;"><span>审批意见：</span></td>
                    <td><textarea id="taApprovalOpinion" rows="5" style="width: 400px;"></textarea></td>
                </tr>
            </table>
        </div>
        <div style="margin-left: 5px; margin-top: 5px; text-align: right;">
            <input type="button" id="btnSave" value="保存" onclick="SaveBackData();" />
            <input type="button" id="btnCancel" value="取消" onclick="window.parent.CloseWindow(0);" />
        </div>
    </div>
</body>
